<?
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'page.inc.php');

$db = new database();

$cmd = @$_REQUEST['cmd'];
if($cmd == 'add')
{
	$content = htmlspecialchars($_REQUEST['content']);
	$name = htmlspecialchars($_REQUEST['name']);
	$contact = trim($_REQUEST['contact']);
	$row['content'] = $content;
	$row['contact'] = $contact;
	$row['name'] = $name;
	$row['ip'] = getIP();
	$row['create_time'] = date("Y-m-d H:i:s");
	$row['update_time'] = date("Y-m-d H:i:s");
	$row['del_flg'] = '0';

	$db->insert($row,'tbl_suggest');
	echo '<script>alert("谢谢您，提交成功！您的建议将在审核后显示。");window.location.href=\''._HOST_ROOT.'\'</script>';
}

$sql_count = "select count(*) as total from `tbl_suggest` where is_ans='1' and del_flg='0'";
$total = $db->loadResult($sql_count);
$curPage = @intval($_REQUEST['p']);
if($curPage < 1) $curPage = 1;
$showNum = _FORVIEWNUM;
$pageLink = "/suggest.php";
$page = new PageClass($total,$curPage,$showNum,$pageLink,5);
$limitStart = $page->limitStart;
$smarty->assign("pageList",$page->pageList);
$sql = "select ts.*,tsa.content as answer from tbl_suggest ts left join tbl_suggest_answer tsa on tsa.sug_id=ts.id where ts.is_ans='1' and ts.del_flg='0' order by ts.create_time desc limit $limitStart,$showNum";
$db->setQuery($sql);
$rows = $db->loadList();
$smarty->assign('rows',$rows);
Display("suggest.tpl");
?>